Need tips on how to create new object using CSV imported data

Hi all DXL Pros,

  DXL Newbie here :-).

  I have a question for  ya, the pros:

 I have User Story requirements(records) in a CSV file which was extracted from JIRA application.

 

Issue key Object Text Summary Parent FRD ID Object Identifier Issue URL
CIAP-42 As a CIAP Admin user, I'd like to do delete an existing user, So that the deleted user can no longer access to CIAP CIAP_USER_MGMT - Delete an existing user NCPS_CIAP_FR_195   http://localhost:8080/projects/CIAP/issues/CIAP-42?filter=allopenissues
CIAP-41 As CIAP Adminstrator, I'd like to create a new user, So that the user can have access to CIAP and performs his/her tasks. CIAP_USER_MGMT - Creating new user account NCPS_CIAP_FR_195   http://localhost:8080/projects/CIAP/issues/CIAP-41?filter=allopenissues
CIAP-27 As CIAP Analyst, I'd like to export Indicators as STIX format, So that I can share the threat info with other external organizations. CIAP_STIX_MGMT -  Exporting the latest version of STIX to share with other sub-systems. NCPS_CIAP_FR_196   http://localhost:8080/projects/CIAP/issues/CIAP-27?filter=allopenissues
CIAP-26 As CIAP Analyst, I'd like to import STIX threat data form external organizations, So that I do threat analysis on cyber threats CIAP_STIX_MGMT - Importing the latest version of STIX to CIAP NCPS_CIAP_FR_196   http://localhost:8080/projects/CIAP/issues/CIAP-26?filter=allopenissues

 

  Now I'd like to tell DOORS DXL to:

  1 - Read in this CSV file - one User Story record at a time

  2 - Create a new User Story Object under Module "US Module"

  I have got  question (1) done.. I think.  I need you guys to give me a hint(s) how to implement the question (2)?  What are the DXL functions that I must use?

  Here is my code for question (1):

=======================================

// Set the fulll path to the input file
string fname = "C:/JiraAndDoors/Doors/Doors_Import/CIAP/Door_Import_All_US_Reqs/CIAP_DOORS_IMPORT_All_US_Reqs_Tue_Jul-03-2018_at_13-12-15.csv"

// Open the input file to read in its records as input stream
Stream inputStream = read(fname)

// Set the input record variable to null
string eachInputRecord = null

// Initialize the counter for User Story input records
int recordCounter = 0

// Create a reference table to store all User Story input records
Skip inputRecordsTable = create()

// Define variable  to hold parent Functional Requirement ID (FR ID)
string FR_ID = null


// Read in one User Story record at a time until the end of the User Story input file.
while(!end(inputStream))
     {
      inputStream >> eachInputRecord
      if(null eachInputRecord )
         break

      if(recordCounter == 0)
        {
         print "Column Header = "  eachInputRecord "\n\n"
         recordCounter++
         continue
        }

        print "record # " recordCounter " = " eachInputRecord "\n\n"

        put(inputRecordsTable, recordCounter, eachInputRecord)

        recordCounter++
       
      }


// Close the input file
close(inputStream)

========================================

 

And here is contents of the input stream - one User Story at a time.

=======================================

Column Header = Issue key,Object Text,Summary,Parent FRD ID,Object Identifier,Issue URL

record # 1 = CIAP-42,"As a CIAP Admin user, I'd like to do delete an existing user, So that the deleted user can no longer access to CIAP",CIAP_USER_MGMT - Delete an existing user,NCPS_CIAP_FR_195,,http://localhost:8080/projects/CIAP/issues/CIAP-42?filter=allopenissues

record # 2 = CIAP-41,"As CIAP Adminstrator, I'd like to create a new user, So that the user can have access to CIAP and performs his/her tasks.",CIAP_USER_MGMT - Creating new user account,NCPS_CIAP_FR_195,,http://localhost:8080/projects/CIAP/issues/CIAP-41?filter=allopenissues

record # 3 = CIAP-27,"As CIAP Analyst, I'd like to export Indicators as STIX format, So that I can share the threat info with other external organizations.",CIAP_STIX_MGMT -  Exporting the latest version of STIX to share with other sub-systems.,NCPS_CIAP_FR_196,,http://localhost:8080/projects/CIAP/issues/CIAP-27?filter=allopenissues

record # 4 = CIAP-26,"As CIAP Analyst, I'd like to import STIX threat data form external organizations, So that I do threat analysis on cyber threats",CIAP_STIX_MGMT - Importing the latest version of STIX to CIAP,NCPS_CIAP_FR_196,,http://localhost:8080/projects/CIAP/issues/CIAP-26?filter=allopenissues

======================================

 

  Please take it easy on the DXL Newbie :-).  Feel free to point out where I made mistake and where should I proceed from this point.  I'm all ears.

  Thanks guys!

  John Nguyen

 

 

 

 

 

 

 

 

 

 

 

 

 


RFT_Newbie - Thu Jul 05 10:40:12 EDT 2018

Re: Need tips on how to create new object using CSV imported data
davidcs - Thu Jul 05 11:02:17 EDT 2018

Have you tried using the CSV importer DOORS provides (File->Import->Spreadsheet)? I'm not saying it is the greatest, but for something like this it should do the trick.Usually takes a little experimenting to get get the data to import correctly, but I have used it in the past successfully. 

Re: Need tips on how to create new object using CSV imported data
RFT_Newbie - Thu Jul 05 11:40:14 EDT 2018

davidcs - Thu Jul 05 11:02:17 EDT 2018

Have you tried using the CSV importer DOORS provides (File->Import->Spreadsheet)? I'm not saying it is the greatest, but for something like this it should do the trick.Usually takes a little experimenting to get get the data to import correctly, but I have used it in the past successfully. 

Hi Dave,

  Thanks for the tips. 

  Yes I did and it works just fine; however, that is not what I'm trying to do.

  I'd like to tell DOORS what to do based on my DXL instructions/code:

  1 - Read in the CSV file.

  2 - Find the destination Module ( in my case it is "US Module").

  3 - Insert the User Story under the "US Module" and create a unique ID  (Object Identifier) for the newly-created record.

  4 - Save the User Story record insertion.

  As my posted code shows, I was able to read in the "User Story" record, on at a time, but I do not know the syntax/functions that I can use to tell DOORS to do steps 2, 3 and 4.

  John Nguyen

 

Re: Need tips on how to create new object using CSV imported data
davidcs - Thu Jul 05 12:43:43 EDT 2018

You really need a CSV parser. I would check if someone has posted the code for one, otherwise you may want to write your own. I would solve that issue first since the format you store the CSV data will determine the code for doing the import.

Re: Need tips on how to create new object using CSV imported data
RFT_Newbie - Thu Jul 05 15:44:14 EDT 2018

RFT_Newbie - Thu Jul 05 11:40:14 EDT 2018

Hi Dave,

  Thanks for the tips. 

  Yes I did and it works just fine; however, that is not what I'm trying to do.

  I'd like to tell DOORS what to do based on my DXL instructions/code:

  1 - Read in the CSV file.

  2 - Find the destination Module ( in my case it is "US Module").

  3 - Insert the User Story under the "US Module" and create a unique ID  (Object Identifier) for the newly-created record.

  4 - Save the User Story record insertion.

  As my posted code shows, I was able to read in the "User Story" record, on at a time, but I do not know the syntax/functions that I can use to tell DOORS to do steps 2, 3 and 4.

  John Nguyen

 

Hi Folks,

  I got it. 

  Here is the code where I can create a new "User Story"  object under the target module "US Module", then I can take the input data from the CSV file and insert into the new object .

  Note: the code below does not show how I get the input text "John is here".  This string "John is here" should  come from the "Object Text" in the CSV file.  I need to do the same for other fields in order to make the "User Story" complete.

  Hope this  primitive code can help other  Newbies like me :-)..

  Any advice, better code tips are welcome.

  Thanks folks!

  John Nguyen

=========================================

 

Folder project_folder = current
Item itemX
Module target_module


for itemX in project_folder do
{

    if(fullName(itemX) == "/John Playground/US  Module")
       {
         target_module = edit(fullName(itemX) "", false)

          print "I am in => "  fullName(itemX) "\n"
          
          Object currentObj = current
          print "Object Identifier = " identifier(currentObj )
          
          Object newUSRequirement = create(below(currentObj))
          
          print "New Object Identifier = " identifier(newUSRequirement)

          newUSRequirement."Object Text" = "John is here"

          save target_module
         
        }

    //close mod

}

=========================================

Re: Need tips on how to create new object using CSV imported data
RFT_Newbie - Tue Jul 10 10:33:39 EDT 2018

RFT_Newbie - Thu Jul 05 15:44:14 EDT 2018

Hi Folks,

  I got it. 

  Here is the code where I can create a new "User Story"  object under the target module "US Module", then I can take the input data from the CSV file and insert into the new object .

  Note: the code below does not show how I get the input text "John is here".  This string "John is here" should  come from the "Object Text" in the CSV file.  I need to do the same for other fields in order to make the "User Story" complete.

  Hope this  primitive code can help other  Newbies like me :-)..

  Any advice, better code tips are welcome.

  Thanks folks!

  John Nguyen

=========================================

 

Folder project_folder = current
Item itemX
Module target_module


for itemX in project_folder do
{

    if(fullName(itemX) == "/John Playground/US  Module")
       {
         target_module = edit(fullName(itemX) "", false)

          print "I am in => "  fullName(itemX) "\n"
          
          Object currentObj = current
          print "Object Identifier = " identifier(currentObj )
          
          Object newUSRequirement = create(below(currentObj))
          
          print "New Object Identifier = " identifier(newUSRequirement)

          newUSRequirement."Object Text" = "John is here"

          save target_module
         
        }

    //close mod

}

=========================================

Hi Folks,

  I found reading CSV file is a lot more challenging and much more complicated than I thought.  You need to be well-versed in Regular Expression and be ready to deal with variance of string format.  There's one case where you have a new line ("\n") character in a cell , then the file reader ( ->) thinks that it hits the end of a row and keeps reading the next part of the same cell as a new row.

  I'm going to abandon this approach and move to OLE where I can read each cell directly from the spreadsheet regardless the content or format of the string in the cell.  In other words, what you see is what you get.

  I'm still learning DXL and I'm  making some good progress.   I'll post the final working version once I got the whole thing work.

  And I will post my scenario as an example of how to:

1 - Directly read in data from CSV file.

2 - Find the desired destination module and create new requirement based on the "read-in" data from step 1

3 - Create a hierarchy relationship between the new requirements and their parent.

4 - Export the newly-created requirements with their newly-created DOORS IDs to a, external CSV file.

It would take me a while to learn more DXL before I can accomplish the goals specified above, but I will get them.  Stay tuned....

Meanwhile if someone can throw me a few bones on how to get there I really appreciate your advice.

Thanks all!

John Nguyen